<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/3/20 0020
 * Time: 11:48
 */

namespace app\sisome\controller;


use think\Db;
use think\Request;

class Team extends Common
{
    /**
     * @name 团队查看
     * @author zay
     * @Date 2020/3/27 0027 11:40
     * @param Request $request
     * @return \think\response\View
     */
    public function team_list(Request $request)
    {
        $start = $request->param('start', 0);
        $end = $request->param('end', 0);
        $orderby = 'id';
        $ordersc = 'desc';
        $list = Db('user');
        if ($start && $end) {
            $list->whereTime('time', '>=', $start);
            $list->whereTime('time', '<=', $end);
        }
        if (!empty($request->param('uname'))) {
            $list->where(['uname' => $request->param('uname')]);
        }
        if ($request->param('ordersc', '')) {
            $orderby ='tj_num';
            $ordersc = $request->param('ordersc');
        }
        $list = $list->order([$orderby => $ordersc])->paginate(20, false, ['query' => Request::instance()->param()]);
        foreach ($list as $k => $v) {
            $data = $v;
            //统计团队人员
            $count = Db('user')->where("FIND_IN_SET({$v['id']},tpath)")
                ->where(['zt'=>1])
                ->count();
            $data['count'] = $count;
            $list->offsetSet($k, $data);
        }
        $this->assign('lists', $list);
        return view();
    }
}